package com.example.controller.wechat;

import com.example.pojo.web.Bike;
import com.example.pojo.web.Result;
import com.example.pojo.wechat.WxPoint;
import com.example.pojo.wechat.WxRegion;
import com.example.service.wechat.WxRegionService;
import com.example.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.concurrent.Callable;

/**
 * @ClassName WxRegionController
 * @Description: com.example.controller.wechat
 * @Auther: xiwd
 * @Date: 2022/4/17 - 04 - 17 - 15:52
 * @version: 1.0
 */
@Controller
@RequestMapping(value = "/region")
public class WxRegionController {
    //properties
    @Autowired
    private WxRegionService wxRegionService;

    //methods
    @ResponseBody
    @RequestMapping(value = "/query/region")
    public Callable<Result> queryRegionForBikes( WxRegion region){
        Callable<Result> callable = new Callable<Result>() {
            @Override
            public Result call() throws Exception {
                List<Bike> bikeList = wxRegionService.queryRegionForBikes(region);
                if (bikeList != null)
                    return ResultUtil.success(1, "查询成功", bikeList);
                else
                    return ResultUtil.error(0, "查询失败");
            }
        };
        return callable;
    }

//    @ResponseBody
//    @RequestMapping(value = "/query/buffer")
//    public Callable<Result> queryBufferForSingleBike(WxPoint wxPoint){
//        System.out.println(wxPoint);
//        //做wxPoin-1m范围内的缓冲区查询，返回第一个对象
//        wxRegionService.queryBufferForSingleBike(wxPoint);
//        return null;
//    }

}
